package neusoft.edu.cn.ui_demo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.List;

import neusoft.edu.cn.ui_demo.beans.Dish;
import neusoft.edu.cn.ui_demo.beans.Result;
import neusoft.edu.cn.ui_demo.beans.lianxi;
import neusoft.edu.cn.ui_demo.recyclerview.RecyclerViewActivity;
import neusoft.edu.cn.ui_demo.retrofitservice.RetrofitService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {

    Button button;//注册
    Button button1;//登录

    EditText editText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = findViewById(R.id.button3);//注册

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Intent intent = new Intent(MainActivity.this,RegisterActivity.class);
                startActivity(intent);
                finish();
            }
        });

        editText = findViewById(R.id.editText2);

        button1 = findViewById(R.id.button);//登录

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent1 = new Intent(MainActivity.this,HomeActivity.class);
                intent1.putExtra("user",editText.getText().toString());

                startActivity(intent1);
                finish();

////                1
//                Retrofit retrofit = new Retrofit.Builder()
//                        .baseUrl("http://172.17.7.95:8080/MenuAPIDemo/")
//                        .addConverterFactory(GsonConverterFactory.create())
//                        .build();
//
////                2
////                获取到本身类的信息
//                RetrofitService retrofitService = retrofit.create(RetrofitService.class);
//
////                3
////                创建一个call对象
//                Call<List<Dish>> dishesCall = retrofitService.getDishes();
//
////                4
//                dishesCall.enqueue(new Callback<List<Dish>>() {
//                    @Override
//                    public void onResponse(Call<List<Dish>> call, Response<List<Dish>> response) {
//                        List<Dish> dishes = response.body();
//                        Toast.makeText(MainActivity.this, "dish --> "+dishes.size(), Toast.LENGTH_SHORT).show();
//                    }
//
//                    @Override
//                    public void onFailure(Call<List<Dish>> call, Throwable t) {
//                        Toast.makeText(MainActivity.this, t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
//                    }
//                });


//                Retrofit retrofit = new Retrofit.Builder()
//                        .baseUrl("http://172.24.10.175:8080/")
//                        .addConverterFactory(GsonConverterFactory.create())
//                        .build();
//
//                RetrofitService retrofitService = retrofit.create(RetrofitService.class);
//
//                Call<lianxi> dishCall = retrofitService.getLianxi("lnn","123456");
//
//                dishCall.enqueue(new Callback<lianxi>() {
//                    @Override
//                    public void onResponse(Call<lianxi> call, Response<lianxi> response) {
//                        lianxi lianxi = response.body();
//                        System.out.println("asd:");
//                        Toast.makeText(MainActivity.this, "ID --> "+lianxi.getUserid(), Toast.LENGTH_SHORT).show();
//                    }
//
//                    @Override
//                    public void onFailure(Call<lianxi> call, Throwable t) {
//                        Toast.makeText(MainActivity.this, t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
//                    }
//
//                });

            }
        });


    }
}
